package socket

import (
	"io/ioutil"
	"net/http"

	"jk/jklog"
)

func GetResponse(url string) *http.Response {
	client := &http.Client{}
	req, _ := http.NewRequest("GET", url, nil)

	res, _ := client.Do(req)

	return res
}

func PrintAllHeader(res *http.Response) {
	l := jklog.L()
	for k, v := range res.Header {
		l.Infoln(k, ": ", v)
	}
}

func PrintAllSenderHeader(res *http.Response) {
	l := jklog.L()
	l.Noneln("Send header")
	for k, v := range res.Request.Header {
		l.Infoln(k, ": ", v)
	}
}

func GetResponseBody(url string) string {
	res := GetResponse(url)

	var body []byte
	if res.StatusCode == 200 {
		body, _ = ioutil.ReadAll(res.Body)
	}

	return string(body)
}
